//
//  PlatformProductTypeListCell.m
//  HAODE
//
//  Created by panquanReabam.com on 15/11/2.
//  Copyright © 2015年 reabam.com. All rights reserved.
//

#import "PlatformProductTypeListCell.h"

#import "UIImageView+WebCache.h"
#import "UIButton+WebCache.h"
#import "HttpRequest.h"
#import "HAODEsingleton.h"
#define  lineColor  [UIColor colorWithRed:228.00/255.0 green:228.00/255.0 blue:228.00/255.0 alpha:1]

#import "UIViewExt.h"
#define ScreenHeight [UIScreen mainScreen].bounds.size.height
#define ScreenWidth  [UIScreen mainScreen].bounds.size.width

@interface PlatformProductTypeListCell ()<UICollectionViewDataSource,UICollectionViewDelegate>
{
    NSArray *array;
    NSInteger collectionHeight;
    UIView *containerView;
    UICollectionView *collection;
    HAODEsingleton*commdity;
}
@end
@implementation PlatformProductTypeListCell{
    
    
}

- (void)awakeFromNib {
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return _imageArrayname.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *str = @"collection";
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:str forIndexPath:indexPath];
    for (UIView *view in [cell.contentView subviews]) {
        [view removeFromSuperview];
    }
    
    UIButton* image=[[UIButton alloc]initWithFrame:CGRectMake(0, 0, cell.width, cell.height)];
    image .titleLabel.font=[UIFont systemFontOfSize:13];
    image.layer.borderWidth = 0.35;
    image.layer.borderColor = qianhuicolor.CGColor;
    
    if ([_imageArrayname[indexPath.row]isEqualToString:commdity.content]) {
//          image.layer.borderColor = luseColor.CGColor;
        [image setBackgroundImage:[UIImage imageNamed:@"gouxuan"] forState:UIControlStateNormal];

    }
    [image setTitle:_imageArrayname[indexPath.row] forState:UIControlStateNormal];
    [image setTitleColor:zhonghuiColor forState:UIControlStateNormal];
    image.userInteractionEnabled=NO;
    
    [cell addSubview:image];
    
    return cell;
}

#define kYOfImageContainer   136.0

- (void)setComment:(MCirclemodel *)comment
{
    
    commdity =[HAODEsingleton shared];
    _comment = comment;
     _imageArrayname= comment.imagePicBig;
     _imageArraycode= comment.imagePicSmall;
    
    
    self.diselabelview.layer.borderWidth = 0.35;
    self.diselabelview.layer.borderColor = qianhuicolor.CGColor;
    self.nameLabel.text = comment.userName;
       [collection removeFromSuperview];
    
    UILabel *quan = [[UILabel alloc]initWithFrame:CGRectMake(10, 15, 15, 15)];
    quan.textColor = luseColor;
    quan.text=@"o";
    quan.font=[UIFont boldSystemFontOfSize:15];
    [self.contentView addSubview:quan];

    
    
    UIImageView *_xianview = [[UIImageView alloc]initWithFrame:CGRectMake(15,50-0.5, ScreenWidth-30, 0.5)];
    _xianview.image=[UIImage imageNamed:@"hengxian"];
    
    [self.contentView addSubview:_xianview];

    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
    layout.itemSize = CGSizeMake((ScreenWidth-45)/4 , 30);
    layout.minimumInteritemSpacing = 1;
    layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
    [collection removeFromSuperview];
    collectionHeight = (comment.imagePicSmall.count/5 +1) *(layout.itemSize.width + 10) -10;
   
    collection = [[UICollectionView alloc]initWithFrame:CGRectMake(12.5, 60, ScreenWidth-25, collectionHeight) collectionViewLayout:layout];
    collection.backgroundColor = [UIColor clearColor];
    collection.alwaysBounceVertical = YES;
    [collection registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"collection"];
    collection.delegate = self;
    collection.dataSource = self;
//  collection.userInteractionEnabled=NO;
    [self.contentView addSubview:collection];
    
    
}

+ (CGFloat)cellHeight:(MCirclemodel *)commentModel
{
    // 手动计算一下containerView的高度，拿此高度再加其它控件的高度
  
    
    
    CGFloat headImageHeight = 60;
    
    //collectionView height
    NSInteger arrayCount = commentModel.imagePicSmall.count;
    
    CGFloat collectionH = (arrayCount/5 +1)* 30;
    
    return  headImageHeight  + collectionH+20;
}



- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    commdity.code=_imageArraycode[indexPath.row];
    commdity.content=_imageArrayname[indexPath.row];
    [_mDelegate tiaojiemian1:_imageArrayname[indexPath.item]];//跳回控制器
    
    
    
//    for (int i=0;  i<_imageArrayname.count; i++) {
//        NSIndexPath *indexPath1 =[NSIndexPath indexPathForRow:i inSection:0 ];
//        UICollectionViewCell* cell1 = [collectionView cellForItemAtIndexPath:indexPath1];
//        cell1.layer.borderWidth = 0.35;
//        cell1.layer.borderColor = qianhuicolor.CGColor;
//    }
// 
//    
//    UICollectionViewCell* cell1 = [collectionView cellForItemAtIndexPath:indexPath];
//    cell1.layer.borderWidth = 0.35;
//    cell1.layer.borderColor = luseColor.CGColor;
//    
   

    


    
    
}
- (void)collectionView:(UICollectionView *)collectionView didHighlightItemAtIndexPath:(NSIndexPath *)indexPath{


}
- (void)collectionView:(UICollectionView *)colView  didUnhighlightItemAtIndexPath:(NSIndexPath *)indexPath
{

    
  
    
}











@end